package org.myrpc.rpc;

import org.myrpc.client.RpcClientProxy;
import org.springframework.beans.factory.FactoryBean;


public class RpcProxyFactoryBean<T> implements FactoryBean<T> {
	/*实现该接口实现动态代理注入spring容器(集体操作类
	他的功能会在RpcClientFactory中通过beandefinitionBuilder来实现
*/
	
	/*这两个属性需要在xml中去配置*/
	private String address;
	
	private Class<T> interfaceClass;//接口的class字节码对象

	
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Class<T> getInterfaceClass() {
		return interfaceClass;
	}

	public void setInterfaceClass(Class<T> interfaceClass) {
		this.interfaceClass = interfaceClass;
	}

	@Override
	public T getObject() throws Exception {
		return new RpcClientProxy(address).getProxy(interfaceClass);
	}

	@Override
	public Class<?> getObjectType() {
		return interfaceClass;
	}

	/*单例设计模式*/
	@Override
	public boolean isSingleton() {
		return true;
	}

}
